Table of Contents

Foundation Objects

Types

All the variables you create in WebScript are objects. Consequently, there is only one data type: id. For more information on the id type, see The id Data Type in Using WebScript.

Sending Messages

To get an object to invoke one of its methods, you send it a message. For example, the following statement:

[colorArray removeAllObjects];

tells the object colorArray to invoke its removeAllObjects method. Message expressions are enclosed in square brackets:

[receiver message];

The receiver is an object and the message is the method you want to invoke and any arguments passed to it. The following are examples of messages with arguments:

[colorArray addObject:newColor];
[colorArray writeToFile:fileName atomically:YES];

In the first statement, newColor is an argument to the method addObject:. In the second statement, fileName and YES are both arguments to the method writeToFile:atomically:.

For more information on messages, see Messaging in WebScript in "Using WebScript."

Representing Objects as Strings

Forthcoming: a discussion of how to represent all kinds of objects as strings using the description method.

Mutable and Immutable Objects

Some objects are immutable; once they are created, they can't be modified. Other objects are mutable. They can be modified at any time. When you create an object, you can often choose to create it as either immutable or mutable. Three kinds of objects discussed in this chapter---strings, arrays, and dictionaries---have both immutable and mutable versions.

For clarity, it's best to use immutable objects wherever possible. Only use a mutable object if you need to modify its contents after you create it.

Determining Equality

Forthcoming: a discussion of how to determine if two objects are equal using the isEqual: method.

Table of Contents Next Section